import { App } from "../../../../src/App";
import { Singleton } from "../../../../src/core/Class";
import { EventConst } from "../../../../src/core/EventConst";

export enum AdType{
    Unknow = -1,
    RewardVideo,
}

class CRewardVideo extends Singleton<CRewardVideo> {
    public playRewardVideo(AdId:string, openID:string,cb:(data:any)=>void){
        App.Event.emit(EventConst.LOCK_SCREEN,true,true);

        if (cc.sys.isNative){
            App.Native.callNative('playRewardVideo',{
                ID:AdId,
                openID:openID
            });
            // 广告加载完成
            App.Event.on('LoadFinished',()=>{
                App.Event.emit(EventConst.LOCK_SCREEN,false,false);
            },this);
    
            // 广告播放完成
            App.Event.on('RewardVerify',(data:any)=>{
                data = data || {RewardName:'null',RewardCount:0,flag:'RewardVideo'};
                cb && cb(data);
                console.log(`RewardVideo.RewardVerify(${JSON.stringify(data)})`);
            },this);
        } else {
            App.popTips(App.getText('native'));
            App.Event.emit(EventConst.LOCK_SCREEN,false,false);
            cb && cb({RewardName:'null',RewardCount:1,flag:'RewardVideo'});
        }
    }
}
const RewardVideo:CRewardVideo = CRewardVideo.getInstance<CRewardVideo>(CRewardVideo);
export default RewardVideo;